include(global.pri)

###########################################################
# INSTALL lib path
###########################################################
head.files                = api/*.h

contains(CONFIG, staticlib) {
    head.path             = $${CYG_INSTALL_PREFIX}/include/nopub/$${TARGET}
    target.path           = $${CYG_INSTALL_PREFIX}/lib/nopub
} else {
    head.path             = $${CYG_INSTALL_PREFIX}/include/$${TARGET}
    target.path           = $${CYG_INSTALL_PREFIX}/lib/cyg
}
# INSTALLS                 += head target

###########################################################
# POST build default copy
###########################################################
PRO_SRC_APIS              = $${_PRO_FILE_PWD_}/api/*.h

contains(CONFIG, staticlib) {
    # static
    PRO_INC_PATH          = $$CYG_NOPUB_INC_PATH/$${TARGET}
    PRO_LIB_PATH          = $$CYG_NOPUB_LIB_PATH
    unix:PRO_LIB_FILE     = $${OUT_PWD}/lib$${TARGET}$${DEBUG_POSTFIX}.a
    
    win32 {
        equals(CYG_OS, 'msvc') {
            PRO_LIB_FILE  = $${OUT_PWD}/$${CYG_TYPE}/$${TARGET}$${DEBUG_POSTFIX}.lib
        } else {
            PRO_LIB_FILE  = $${OUT_PWD}/$${CYG_TYPE}/lib$${TARGET}$${DEBUG_POSTFIX}.a
        }
    }

} else {
    # shared
    CONFIG               += plugin
    PRO_INC_PATH          = $$CYG_INC_PATH/$${TARGET}
    PRO_LIB_PATH          = $$CYG_LIB_PATH
    unix:PRO_LIB_FILE     = $${OUT_PWD}/lib$${TARGET}$${DEBUG_POSTFIX}.so

    # msvc or mingw
    win32 {
        PRO_LIB_FILE     += $${OUT_PWD}/$${CYG_TYPE}/$${TARGET}$${DEBUG_POSTFIX}.dll
        equals(CYG_OS, 'msvc') {
            PRO_LIB_FILE += $${OUT_PWD}/$${CYG_TYPE}/$${TARGET}$${DEBUG_POSTFIX}.lib
        } else {
            PRO_LIB_FILE += $${OUT_PWD}/$${CYG_TYPE}/lib$${TARGET}$${DEBUG_POSTFIX}.a
        }
    }
}

win32 {
    PRO_SRC_APIS          = $$replace(PRO_SRC_APIS, /, \\)
    PRO_LIB_FILE          = $$replace(PRO_LIB_FILE, /, \\)
    PRO_INC_PATH          = $$replace(PRO_INC_PATH, /, \\)
    PRO_LIB_PATH          = $$replace(PRO_LIB_PATH, /, \\)

    mkdir_inc             = (if not exist $${PRO_INC_PATH} $${QMAKE_MKDIR} $${PRO_INC_PATH})
    mkdir_lib             = (if not exist $${PRO_LIB_PATH} $${QMAKE_MKDIR} $${PRO_LIB_PATH})

    copy_apis             = (for %%i in ($${PRO_SRC_APIS}) do $${QMAKE_COPY_FILE} %%i $${PRO_INC_PATH})
    copy_libs             = (for %%i in ($${PRO_LIB_FILE}) do $${QMAKE_COPY_FILE} %%i $${PRO_LIB_PATH})

    QMAKE_POST_LINK      += $$mkdir_inc && $$mkdir_lib && $$copy_apis && $$copy_libs
}

unix {
    mkdir_inc             = $${QMAKE_MKDIR} $${PRO_INC_PATH}
    mkdir_lib             = $${QMAKE_MKDIR} $${PRO_LIB_PATH}

    copy_apis             = $${QMAKE_COPY_FILE} $${PRO_SRC_APIS} $${PRO_INC_PATH}
    copy_libs             = $${QMAKE_COPY_FILE} $${PRO_LIB_FILE} $${PRO_LIB_PATH}
    QMAKE_POST_LINK      += $$mkdir_inc; $$mkdir_lib; $$copy_apis; $$copy_libs
}
